package zhoug.zui.round;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;

import zhoug.zui.alpha.ZUIAlphaTextView;
import zhoug.zui.utils.ZUIViewHelper;

/**
 * 圆形TextView
 * @Author 35574
 * @Date 2020/7/24
 * @Description
 */
public class ZUIRoundTextView extends ZUIAlphaTextView {
    private static final String TAG = ">>>ZUIRoundTextView";
    private static final boolean DEBUG = false;

    private ZUIViewHelper _mRoundViewHelper;

    public ZUIRoundTextView(Context context) {
        this(context, null);
    }

    public ZUIRoundTextView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ZUIRoundTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        this(context, attrs, defStyleAttr,0);
    }

    public ZUIRoundTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        _getZUIViewHelper().parseAttribute(context, attrs, defStyleAttr, defStyleRes);
    }

    private ZUIViewHelper _getZUIViewHelper(){
        if(_mRoundViewHelper==null){
            _mRoundViewHelper = new ZUIViewHelper(this);
        }
        return _mRoundViewHelper;
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        _getZUIViewHelper().onSizeChanged(w, h);
    }


    @Override
    public void setPressed(boolean pressed) {
        super.setPressed(pressed);
        _getZUIViewHelper().onPressedChanged(this,pressed);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        _getZUIViewHelper().onDraw(canvas);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int size = _getZUIViewHelper().measureSize(getMeasuredWidth(), getMeasuredHeight());
        if (size > 0) {
            setMeasuredDimension(size, size);
        }
    }

    public void setBorder(int borderSize){
        _getZUIViewHelper().setBorder(borderSize);
    }

    public void setBorderColor(int borderColor){
        _getZUIViewHelper().setBorderColor(borderColor);
        _getZUIViewHelper().onPressedChanged(this,isPressed());
    }

}
